package com.zzx.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class WebConfig  implements WebMvcConfigurer{

    /**
     * 跨域
     * @param registry
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        /*任意请求*/
        registry.addMapping("/**")
                /*允许来源*/
                .allowedOrigins("*")
                /*允许任意请求方式*/
                .allowedMethods("PUT","DELETE","GET","POST")
                /*允许任意请求头*/
                .allowedHeaders("*")
                /*暴露请求头*/
//                .exposedHeaders("*")
                .allowCredentials(false).maxAge(3600);
        WebMvcConfigurer.super.addCorsMappings(registry);
    }
}
